Skip to main content

REST API methods

These methods make usage of the Home Assistant REST API.


checkConfig

Important

This method can be executed only by admin users.

This method allows one to validate the Home Assistant configuration. It returns a promise which resolves in an object with a result property. The result property can have two values, valid or invalid. This object will also have two optional properties, errors and warnings that will be filled with the corresponding errors or warnings coming from the Home Assistant configuration check.

custom-sidebar-config.yaml
order:
- new_item: true
item: 'check config'
icon: 'mdi:check-circle-outline'
on_click:
action: 'javascript'
code: |
checkConfig()
.then((response) => {
if (response.result === 'valid') {
openAlertDialog({
title: 'Configuration valid',
text: response.warnings
? `The configuration is valid but with warnings: ${response.warnings}`
: 'The configuration is valid'
});
} else {
openAlertDialog({
title: 'Configuration with errors',
text: response.errors
});
}
});

renderTemplate

Important

This method can be executed only by admin users.

This method accepts a Jinja template string as a parameter and it will return a promise which resolves in the result of the template.

custom-sidebar-config.yaml
order:
- new_item: true
item: 'date'
icon: 'mdi:clock-time-eight'
on_click:
action: 'javascript'
code: |
renderTemplate(
"The date is {{ as_timestamp(now()) | timestamp_custom('%Y-%m-%d') }}"
).then((result) => {
openAlertDialog({
title: 'Date of today',
text: result
});
});

callService

Important

Some services can be executed only by admin users, for example, restarting Home Assistant.

This method will call a Home Assistant service (renamed some time ago to actions). It allows one to call a service from a JavaScript template. This method needs three parameters, the first one is the domain, the second the type of service and the third an object with the data needed by the service.

custom-sidebar-config.yaml
order:
- new_item: true
item: 'lights'
icon: 'mdi:lightbulb-on'
on_click:
action: 'javascript'
code: |
callService(
'light',
'toggle',
{
entity_id: user_name === 'Miriam'
? 'light.miriam_room'
: 'light.my_room'
}
);